import * as types from './actionTypes';
import Util from '../common/utils';


//门票列表
export let fetchTicketList = () => {
	let url = global.U + '/api/uc/tc/appTicketPlaceService/appJuPlaceList';

    return dispatch => {

        // 请求门票数据
        dispatch(beginTicketlist());
        return Util.post(url, {'sale_category' : 'a14'}, (response) => {
            dispatch(receiveTicketlist(response.data));
        }, (error) => {
            console.log('Fetch Ticket list error: ' + error);
            dispatch(receiveTicketlist([]));
        });
    }
};

export let beginTicketlist = () => {
	return {
		'type' : types.FETCH_TICKET_LIST,
	}
};

export let receiveTicketlist = (ticketList) => {
	return {
		'type' : types.RECEIVE_TICKET_LIST,
		'ticketList' : ticketList
	}
};




//门票详情
export let fetchTicketInfo = (id) => {
    let url = global.U + '/api/us/tc/sale/saleInfo';

    return dispatch => {

        // 请求门票数据
        dispatch(beginTicketInfo());
        return Util.post(url, {'id' : id}, (response) => {
            console.log('ticket info');
            console.log(response);
            dispatch(receiveTicketInfo(response.data));
        }, (error) => {
            console.log('Fetch Ticket info error: ' + error);
            dispatch(receiveTicketInfo([]));
        });
    }
};

export let beginTicketInfo = () => {
    return {
        'type' : types.FETCH_TICKET_INFO,
        'getting' : true,
    }
};

export let receiveTicketInfo = (ticketInfo) => {
    return {
        'type' : types.RECEIVE_TICKET_INFO,
        'ticketInfo' : ticketInfo,
        'getting' : false,
    }
};



